package com.ruoyi.community.controller.wxApi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.community.domain.Complain;
import com.ruoyi.community.service.IComplainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 投诉意见Controller
 *
 * @author lj
 * @date 2022-02-22
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/wx/community/complain")
@Api(tags = {"投诉意见"})
public class WxComplainController extends BaseController
{
    @Autowired
    private IComplainService complainService;

    /**
     * 查询投诉意见列表
     */
    @ApiOperation(value = "查询投诉意见列表")
    @GetMapping("/list")
    public TableDataInfo list(Complain complain)
    {
        startPage();
        List<Complain> list = complainService.selectComplainList(complain);
        if (ObjectUtils.isEmpty(list)){
            return getNoDataTable(list);
        }
        return getDataTable(list);
    }

    /**
     * 导出投诉意见列表
     */
    @ApiOperation(value = "导出投诉意见列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Complain complain)
    {
        List<Complain> list = complainService.selectComplainList(complain);
        ExcelUtil<Complain> util = new ExcelUtil<Complain>(Complain.class);
        util.exportExcel(response, list, "投诉意见数据");
    }

    /**
     * 获取投诉意见详细信息
     */
    @ApiOperation(value = "获取投诉意见详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(Long id)
    {
        return AjaxResult.success(complainService.selectComplainById(id));
    }

    /**
     * 新增投诉意见
     */
    @ApiOperation(value = "新增投诉意见")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Complain complain)
    {
        return toAjax(complainService.insertComplain(complain));
    }

    /**
     * 修改投诉意见
     */
    @ApiOperation(value = "修改投诉意见")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody Complain complain)
    {
        return toAjax(complainService.updateComplain(complain));
    }

    /**
     * 删除投诉意见
     */
    @ApiOperation(value = "删除投诉意见")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        Long[] ids= {id};
        return toAjax(complainService.updateComplainByIds(ids));
    }
}
